import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    login: (data) => request.post('/user/login', data),
    banner: {
        ...defaultApi('banner')
    },
    cdk: {
        ...defaultApi('cdk'),
        batchCreate: (data) => request.post(`/cdk/batchCreate`, data)
    },
    news: {
        ...defaultApi('news')
    },
    newsCategory: {
        ...defaultApi('newsCategory')
    },
    product: {
        ...defaultApi('product')
    },
    productCategory: {
        ...defaultApi('productCategory')
    },
    productItem: {
        ...defaultApi('productItem')
    },
    file: {
        ...defaultApi('file')
    },
    user: {
        ...defaultApi('user')
    },
    order: {
        ...defaultApi('order'),
        refundConfirm: (data) => request.post(`/order/refund/confirm`, data)
    },
    userProduct: {
        ...defaultApi('userProduct')
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
